package com.kedacom.emptyproject.map.widget

import android.content.Context
import android.support.constraint.ConstraintLayout
import android.util.AttributeSet
import android.view.ViewGroup
import com.kedacom.emptyproject.util.dp2px

/**
 * 中间、预览模块
 * @author GuanHaoran
 * @description:
 * @date :2020/10/16 2:55 PM
 */
class MyLayerBottomInfoView(context: Context, attributes: AttributeSet?, defStyle: Int = 0) :
    ConstraintLayout(context, attributes, defStyle) {

    private var params: ViewGroup.LayoutParams? = null

    constructor(ctx: Context, attributes: AttributeSet?) : this(
        context = ctx,
        attributes = attributes
    )

    constructor(ctx: Context) : this(context = ctx, attributes = null)


    init {

        params = layoutParams
    }

    fun setPoi(midOffset: Float, float: Float) {
//        0.0  - 0.5 - 1.0
//        this.alpha = 1 - (0.5 - float)
//        this.alpha =(1 - Math.abs((midOffset- float) *2f)).toFloat()
//        this.alpha = (1 - (midOffset - float) * 4)


        //设置透明度
        if (float >= midOffset) {
            this.alpha = 1f
        } else {
            this.alpha = 1 / midOffset * float
        }
//        this.alpha = (1 - (midOffset - float) * 4)

//        setPoiHeight((1 - (midOffset - float) * 5))
//        setPoiHeight(float)
    }

    private fun setPoiHeight(offset: Float) {

        if (params == null)
            params = layoutParams

        params?.apply {
            if (offset in 0.0..1.0) {
                height = (220 + (220 * (1 - (1 - (0.5 - offset)))).toFloat()).dp2px()
            }
            layoutParams = this
        }
    }


}